package m1.server;

import m1.server.config.ServerConf;
import m2.component.Component;
import m2.links.Binding;

public class Server extends Component{

	private static Server server;
	private Binding receiveRequServExternSock;
	private Binding sendRequServExternSockOut;
	/*private Binding serverOutConfIn;
	private Binding serverInConfOut;*/
	
	/**
	 * 
	 */
	private Server(){	
		ServerInterfaceProvided serverInterfaceProvided = new ServerInterfaceProvided();
		ServerInterfaceRequired serverInterfaceRequired = new ServerInterfaceRequired();
		addComponentInterfaceProvided(serverInterfaceProvided);
		addComponentInterfaceRequired(serverInterfaceRequired);
		addProvidedPort(new SendRequestServer("SendRequestServer"), new ServerOut("ServerOut"));
		addRequiredPort(new ReceiveRequestServer("ReceiveRequestServer"), new ServerIn("ServerIn"));
		serverInterfaceProvided.buildService();
		serverInterfaceRequired.buildService();
		addConfig(ServerConf.getInstance());					
				
		//********Binding connectionManager-server********
		receiveRequServExternSock = new Binding();
		receiveRequServExternSock.bindingIn(this, getRequiredPort("ReceiveRequestServer"),
				getConfig(), getConfig().getComponent("ConnectionManager").getProvidedPort("ExternalSocket"));
		
		sendRequServExternSockOut = new Binding();
		sendRequServExternSockOut.bindingIn(getConfig(), getConfig().getComponent("ConnectionManager")
				.getRequiredPort("ExternalSocketOut"), this, getProvidedPort("SendRequestServer"));	

		//********Binding server-conf********
		/*serverOutConfIn = new Binding();
		serverOutConfIn.bindingIn(this, getProvidedPort("ServerOut"), getConfig(), getConfig().getRequiredPort("ConfIn"));*/
				
		/*serverInConfOut = new Binding();
		serverInConfOut.bindingOut(getConfig(), getConfig().getProvidedPort("ConfOut"), this, getRequiredPort("ServerIn"));*/
		
	} 
	
	/**
	 * 
	 * @return
	 */
	public static Server getInstance(){
		if (server == null){
			server = new Server();
		}
		return server;
	}
		
}
